package com.ruoyi.shop.system.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.shop.api.domain.Shop;
import com.ruoyi.shop.system.service.SysShopService;
import com.ruoyi.shop.verification.domain.ShopVerification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping
public class SysShopController {

    @Autowired
    SysShopService sysShopService;

    @RequestMapping("/register")
    public AjaxResult register(@RequestBody Map<String, Object> map) {
        ObjectMapper objectMapper = new ObjectMapper();

        Shop shop = objectMapper.convertValue(map.get("shop"), Shop.class);
        ShopVerification shopVerification = objectMapper.convertValue(map.get("shopVerification"), ShopVerification.class);

        System.out.println(sysShopService.register(shop, shopVerification));
        return AjaxResult.success();
    }

    @RequestMapping("/login")
    public AjaxResult login(@RequestBody Map<String, Object> data) {
        System.out.println("111111111");
        // 验证码 待做
        String mobile = data.get("mobile").toString();
        String verifyCode = data.get("verifyCode").toString();
        return sysShopService.login(mobile, verifyCode);
    }

}
